class Solution(object):
    def sortArrayByParity(self, nums):
        """
        :type nums: List[int]
        :rtype: List[int]
        """
        n = len(nums)
        left_index = 0
        right_index = n - 1
        while right_index > left_index:
            if nums[left_index] % 2 == 0:
                left_index += 1
            else:
                if nums[right_index] % 2 == 0:
                    temp = nums[left_index]
                    nums[left_index] = nums[right_index]
                    nums[right_index] = temp
                    left_index += 1
                    right_index -= 1
                else:
                    right_index -= 1
        return nums


data = Solution()
nums = [3, 1, 2, 4]
print(data.sortArrayByParity(nums))